//
//  WRYTagCell.m
//  BaiSiBuJie
//
//  Created by wry on 16/4/28.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "WRYTagCell.h"
#import "WRYSubTagItem.h"
#import <UIImageView+WebCache.h>
#import <SVProgressHUD/SVProgressHUD.h>

@interface WRYTagCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (weak, nonatomic) IBOutlet UILabel *numberView;

@end

@implementation WRYTagCell


- (void)awakeFromNib {
    [super awakeFromNib];
    // 只会调用一次
    // 当对象从xib加载完成就会调用
    //做初始化
//    //设置圆角
//    self.iconView.layer.cornerRadius=self.iconView.width*0.5;
//    self.iconView.layer.masksToBounds=YES;
    
}


-(void)setCellItem:(WRYSubTagItem *)cellItem
{
    _cellItem=cellItem;
    //1.名称
    _nameView.text=cellItem.theme_name;

    //2.订阅数
    //3.设置订阅数字 5000人订阅 5万人订阅
    NSInteger num=[cellItem.sub_number integerValue];
    NSString * numStr=[NSString stringWithFormat:@"%zd人订阅",num];
    if (num>10000) {
            CGFloat numF=num/10000.0;
            numStr=[NSString stringWithFormat:@"%.1f万人订阅",numF];
            numStr=[numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
        
    }
    _numberView.text=numStr;

    //4.图标,占位图片
    [_iconView sd_setImageWithURL:[NSURL URLWithString:cellItem.image_list]placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        //图片裁剪方法设置圆形图标
        if (image==nil) {
            //排除没有图片的情况
            return ;
        }
        //1.开启图形上下文,scale:比例因素 像素与点比例 2:1 , 1:1 , 3:1 ,传0代表自动识别当前比例因素
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        
        //2.描述裁剪区域
        UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        //3.裁剪
        [path addClip];
        //4.画图
        [image drawAtPoint:CGPointZero];
        
        //5.取出图片
        image=UIGraphicsGetImageFromCurrentImageContext();
        //6.关闭图形上行文
        UIGraphicsEndImageContext();
       
        //7.设置头像
        _iconView.image=image;
        
    }] ;
    
}

//修改分割线为全屏方式3,重写cell的setFrame
-(void)setFrame:(CGRect)frame
{
    frame.size.height-=2;
    [super setFrame:frame];
}











@end
